@layout("/common/_curd/_container.html"){
<style>
	.title1{
		width: 100%;
		text-align: center;
		margin: 0 auto;
	}
	.top1{
		font-size: 20px;
		font-weight: bold;
	}
	.title2{
		display: flex;
		width: 100%;
		margin: 0 auto;
		align-items: center;
		justify-content: space-between;
	}
	/*.company{*/
		/*text-decoration:underline*/
	/*}*/
</style>

		<input type="hidden" value="${orderId}" id="orderId">
		<div class="content">
			<div class="title1">
				<span class="top1">新苏南集团</span>
			</div>
			<div class="title1">
				<select id="did" name="sn_order_in.d_id" >
					<option value="0">未选择</option>
					@for(s in company){
						<option value="${s.id}">${s.name}</option>
					@}
				</select>
				<span class="top1">汽车销售服务有限公司采购申请单</span>
			</div>
			<div class="title2">
				<div class="left">
					<span>供货商</span>
					<select id="suppliers" name="sn_order_in.supplier" >
						<option value="0">未选择</option>
						@for(s in suppliers){
							<option value="${s.id}">${s.name}</option>
						@}

					</select>
				</div>
				<div class="middle">
					<span>采购类别：</span>
					<label class="radio-inline">
						<input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="1"> 精品装潢
					</label>
					<label class="radio-inline">
						<input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="2"> 外网配件
					</label>
				</div>
				<div>
					<span>日期：</span>
					<input type="text" id="apply_date">
				</div>
			</div>
			<div>
				<button type="btn btn-success" id="_add" onclick="addtr()">新增</button>
				<button type="btn btn-success" id="_edit" onclick="edittr()">修改</button>
				<button type="btn btn-success" id="_remove" onclick="remove()">删除</button>
			</div>
			<table class="table table-bordered" id="orderLog">
				<tr>
					<td>#</td>
					<td>
						商品编号
					</td>
					<td>
						商品名称
					</td>
					<td>
						单位
					</td>
					<td>
						数量
					</td>
					<td>
						单价
					</td>
					<td>
						金额
					</td>
				</tr>

				<tr>
					<td>
						<input type="radio" name="liebiaoid" id="ask1" value="1">
					</td>
					<td>
						<input type="text" name="" class="form-control">
					</td>
					<td>
						<input type="text" name="" class="form-control">
					</td>
					<td>
						<input type="text" name="" class="form-control">
					</td>
					<td>
						<input type="text" name="" class="form-control">
					</td>
					<td>
						<input type="text" name="" class="form-control">
					</td>
					<td>
						<input type="text" name="" class="form-control">
					</td>
				</tr>
				<tr>
					<td>
							<input type="radio" name="liebiaoid" id="ask2" value="2">
					</td>
					<td>
						商品编号
					</td>
					<td>
						商品名称
					</td>
					<td>
						单位
					</td>
					<td>
						数量
					</td>
					<td>
						单价
					</td>
					<td>
						金额
					</td>
				</tr>
			</table>
		</div>

		<div class="clearfix form-actions center" style="margin-top:15px;margin-bottom:5px;">
			<div class="col-md-offset-1 col-md-10">
				<button class="btn btn-info" type="submit" onclick="addapply()" id="btn_save1">
					<i class="ace-icon fa fa-check bigger-110"></i>
					提交采购申请
				</button>

				&nbsp; &nbsp; &nbsp;
				<button class="btn" type="button" id="btn_closes" onclick="closes()">
					<i class="ace-icon fa fa-close bigger-110"></i>
					关闭
				</button>
			</div>
		</div>


		<script>
			closes = function(){
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
			}

			addapply = function(){
				var type = $('input:radio:checked').val();
				if(type !=2 && type !=1){
					layer.msg("请选择采购类型")
					return false;
				}
				console.log($("#did").val())
                var ajaxURL = "/snOrderIn/update"
				var ajaxData = {
                    "sn_order_in.id":${orderId},
                    "sn_order_in.type":$('input:radio:checked').val(),
                    "sn_order_in.addtime":$("#apply_date").val(),
					"sn_order_in.d_id":$("#did").val(),
                    "sn_order_in.s_id":$("#suppliers").val(),
                    "sn_order_in.status":1
				}
                $.post(ajaxURL,ajaxData,function (res) {
                    if(res["success"]){
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    }
                });

			}

			$(function () {
				initTable();
            })
            var inithtml = '<tr><td>#</td><td>商品编号</td><td>' +
                '商品名称' +
                '</td><td>' +
                '单位' +
                '</td><td>' +
                '数量' +
                '</td><td>' +
                '单价' +
                '</td><td>' +
                '金额' +
                '</td></tr>'
			addtr = function () {
                var index = layer.open({
                    type: 2,
                    title:'新增',
                    area: ['100%', '100%'],
                    maxmin:true,
                    shadeClose: true, //点击遮罩关闭

                    content:  '/snOrderInlog/add?orderId=' + $("#orderId").val()
                    ,end:function () {
                        initTable();
                    }
                });

                this.layerIndex = index;
            }

			edittr = function () {
				var id =$('input[name="table_rows"]:checked').val()
				if(!id>0){
					layer.msg("请选择要修改的项")
					return false;
				}
				var index = layer.open({
					type: 2,
					title:'修改',
					area: ['100%', '100%'],
					maxmin:true,
					shadeClose: true, //点击遮罩关闭

					content:  '/snOrderInlog/edit/' + id
					,end:function () {
						initTable();
					}
				});

				this.layerIndex = index;
			}


			remove = function(){
				var id =$('input[name="table_rows"]:checked').val()
				if(!id>0){
					layer.msg("请选择要删除的项")
					return false;
				}

				$.post("/snOrderInlog/remove",{ids:id},function (res) {
					if(res["success"]){
						initTable()
						layer.msg("删除成功!")
					}
				});

			}


            initTable = function () {
                var ajaxURL = "/snOrderInlog/list?orderId="+$("#orderId").val();

                $.get(ajaxURL,null,function (res) {
                    $('#orderLog').empty();
                    var html = ""
					if(res.records>0){
                        for(var i = 0;i<res.records;i++){
                            html += '<tr><td>' +
                                '<input type="radio" name="table_rows" value="'+res.rows[i].id+'">' +
                                '</td><td>商品编号</td><td>' +
                                res.rows[i].g_name +
                                '</td><td>' +
                                res.rows[i].g_unit +
                                '</td><td>' +
                                res.rows[i].num +
                                '</td><td>' +
                                res.rows[i].price +
                                '</td><td>' +
                                res.rows[i].totle_price +
                                '</td></tr>'
                        }
					}else {
					    html = '<tr><td colspan="7" style="text-align: center;">没有记录</td></tr>';
					}

                    $('#orderLog').append(inithtml+html)
                });
            }
		</script>


<script src="/static/blade/js/laydate/laydate.js"></script>
<script>
	laydate.render({
		elem: '#apply_date'
		,value:new Date()
	});
</script>

@}
